///////////////////////////////////////////////////////////////////
// Student name:Jon Hersack and Caleb Reinking
// Course: COSC 3403
// Assignment: #7 - Initial Software Construction
// File name:UserInterface.java
// Purpose: Provides a UI to be printed to the console, based on the
//          information stored inside the team and player classes.
// Assumptions:none known
// Limitations: Most of the display at this point is hard-coded because no display
//              updating is being done at this point. This will change for the
//              next increments.
// Development Computer: Intel
// Operating System: windows
// Integrated Development Environment (IDE): netbeans 6.5
// Compiler: Javac: java 1.6.0_13
///////////////////////////////////////////////////////////////////

import java.util.*;

public class UserInterface
{

    String currentQuestion;
    Vector<Team> teamVect;
    Scanner console = new Scanner(System.in);
    //int activeTeam;

    //################################################
    UserInterface()
    {
        currentQuestion = "";

    } //end constructor

    //#################################################
    void cls()
    {
        for( int i = 0 ; i < 40 ; i++ )
            System.out.println();

    }//end cls

    //#################################################
    void displayBoard(int activeTeam ,Vector<Team> teams )
    {
        //debug show computer hands
        //Hand tempHand = teams.get(activeTeam).getPlayer(teams.get(activeTeam).activePlayer).getHand();//active player
        Hand tempHand = teams.get(0).getPlayer(0).getHand();//always human player hand

        //stops board swapping
        activeTeam=0;//comment out to have rotating board for current player's perspective
        int otherTeam = (activeTeam+1)%(teams.size());



        System.out.printf("+---------------------------------------------------------------------------+\n" );
        //prints current team's scores
        System.out.printf("| TEAM HAND MILEAGE: %-6d                          TEAM GAME SCORE: %-6d|\n",
                teams.get(otherTeam).handMileage,teams.get(otherTeam).gameScore );
        System.out.printf("|     +------+------+------+------+      +--------+    +--------+           |\n" );
        System.out.printf("|     |  RoW |  DA  |  PP  |  ET  |      |%-8s|    |%-8s| SL: %-5s |\n",
                teams.get(otherTeam).getBPCard().toStringRep().get(0),//battle pile
                teams.get(otherTeam).getSPCard().toStringRep().get(0),
                teams.get(otherTeam).getSpeedLimit());//speed pile

        System.out.printf("|     |      |      |      |      |      |%-8s|    |%-8s|           |\n",
                teams.get(otherTeam).getBPCard().toStringRep().get(1),//battle pile
                teams.get(otherTeam).getSPCard().toStringRep().get(1));//speed pile);

        System.out.printf("|     |      |      |      |      |      |%-8s|    |%-8s| 200s LEFT |\n",
                teams.get(otherTeam).getBPCard().toStringRep().get(2),//battle pile
                teams.get(otherTeam).getSPCard().toStringRep().get(2));//speed pile);

        System.out.printf("|     |  %-3s |  %-3s |  %-3s |  %-3s |      |        |    |        | --------- |\n",
               teams.get(otherTeam).getSafety(0),teams.get(otherTeam).getSafety(1),
               teams.get(otherTeam).getSafety(2),teams.get(otherTeam).getSafety(3));
        
        System.out.printf("|     |      |      |      |      |      |   BP   |    |   SP   |     %-1d     |\n",
               teams.get(otherTeam).getTwoHundredsLeft());
        System.out.printf("|     +------+------+------+------+      +--------+    +--------+           |\n" );
        System.out.printf("+============ SAFETY AREA ====================  PLAY AREA ==================+\n" );
        System.out.printf("|     +------+------+------+------+      +--------+    +--------+           |\n" );
        System.out.printf("|     |  RoW |  DA  |  PP  |  ET  |      |%-8s|    |%-8s| SL: %-5s |\n",           
                teams.get(activeTeam).getBPCard().toStringRep().get(0),//battle pile
                teams.get(activeTeam).getSPCard().toStringRep().get(0),
                teams.get(activeTeam).getSpeedLimit());//speed pile

        System.out.printf("|     |      |      |      |      |      |%-8s|    |%-8s|           |\n",
                teams.get(activeTeam).getBPCard().toStringRep().get(1),//battle pile
                teams.get(activeTeam).getSPCard().toStringRep().get(1));//speed pile);

        System.out.printf("|     |      |      |      |      |      |%-8s|    |%-8s| 200s LEFT |\n",
                teams.get(activeTeam).getBPCard().toStringRep().get(2),//battle pile
                teams.get(activeTeam).getSPCard().toStringRep().get(2));//speed pile);
        
        System.out.printf("|     |  %-3s |  %-3s |  %-3s |  %-3s |      |        |    |        | --------- |\n",
               teams.get(activeTeam).getSafety(0),teams.get(activeTeam).getSafety(1),
               teams.get(activeTeam).getSafety(2),teams.get(activeTeam).getSafety(3));
        System.out.printf("|     |      |      |      |      |      |   BP   |    |   SP   |     %-1d     |\n",
                teams.get(activeTeam).getTwoHundredsLeft());
        System.out.printf("|     +------+------+------+------+      +--------+    +--------+           |\n" );
//debug System.out.printf("|%32s's hand:                                   |\n",teams.get(activeTeam).getActivePlayer().name );
        //always human hand
        System.out.printf("|%32s's hand:                                   |\n",teams.get(0).getPlayer(0).name );
        System.out.printf("|  +-------+ +-------+ +-------+ +-------+ +-------+ +-------+ +-------+    |\n" );

        // prints the contents of the first player's hand to the screen
        for( int i = 0 ; i < 3 ; i++ )
        {
            System.out.printf("|  ");

            for( int j = 0 ; j < 7 ; j++ )
            {
                if( tempHand.size() > j )
                    System.out.printf("|%-7s| ", tempHand.getCard(j).toStringRep().get(i));
                else System.out.printf("|       | ");
            } // end for j


            System.out.printf("   |\n" );
        } // end for i

        System.out.printf("|  |     1 | |     2 | |     3 | |     4 | |     5 | |     6 | |     7 |    |\n" );
        System.out.printf("|  +-------+ +-------+ +-------+ +-------+ +-------+ +-------+ +-------+    |\n" );
        System.out.printf("| TEAM HAND MILEAGE: %-6d                          TEAM GAME SCORE: %-6d|\n",
                teams.get(activeTeam).handMileage,teams.get(activeTeam).gameScore );
        System.out.printf("+---------------------------------------------------------------------------+\n" );

    }//end displayBoard

    //##################################################
    void displayPrompt( int activeTeam, Vector<Team> teamVect )
    {
        System.out.printf("  Current Player: %s\n", 
                          teamVect.get(activeTeam).getActivePlayer().getName() );
        System.out.printf("  %s  ", currentQuestion);
    } // end displayPrompt

    void display( int activeTeam, Vector<Team> teamVect )
    {
        cls();
        displayBoard(activeTeam,teamVect);
        displayPrompt( activeTeam, teamVect );
    } // end displays

    //##############################################
    String[][] getNames()
    {
         String[][] names = new String[2][3];
         System.out.print("What is team 1's name? : ");
         names[0][0]=console.nextLine();
         System.out.print("What is player 1's name? : ");
         names[0][1]=console.nextLine();
         System.out.print("What is player 2's name? : ");
         names[0][2]=console.nextLine();
         System.out.print("What is team 2's name? : ");
         names[1][0]=console.nextLine();
         System.out.print("What is player 3's name? : ");
         names[1][1]=console.nextLine();
         System.out.print("What is player 4's name? : ");
         names[1][2]=console.nextLine();
        return names;
    }

    //##############################################
    int getGameType()
    {
       System.out.print("Would you like 3 or 4 computer players?(3,4): ");
       return console.nextInt();
    }

    //#################################################
    void askUser(String question)
    {
        currentQuestion = question;
        return;
    }//end askUser

    //#################################################
    void clearQuestion()
    {
        currentQuestion = "\n";
    }//end tellUser

    //#########################################################################
    void printMainSplash()
    {
        cls();
        System.out.println("+===========================================================================+");
        System.out.println("|                                                                           |");
        System.out.println("|                     _   _        __     __                                |");
        System.out.println("|                    /'\\_/`\\   __ /\\_ \\  /\\_ \\                              |");
        System.out.println("|                   /\\      \\ /\\_\\\\//\\ \\ \\//\\ \\       __                    |");
        System.out.println("|                   \\ \\ \\__\\ \\\\/\\ \\ \\ \\ \\  \\ \\ \\    /'__`\\                  |");
        System.out.println("|                    \\ \\ \\_/\\ \\\\ \\ \\ \\_\\ \\_ \\_\\ \\_ /\\  __/                  |");
        System.out.println("|                     \\ \\_\\\\ \\_\\\\ \\_\\/\\____\\/\\____\\\\ \\____\\                 |");
        System.out.println("|                      \\/_/ \\/_/ \\/_/\\/____/\\/____/ \\/____/                 |");
        System.out.println("|              ____                                                         |");
        System.out.println("|             /\\  _`\\                                                       |");
        System.out.println("|             \\ \\ \\ \\ \\    ___    _ __    ___       __     ____             |");
        System.out.println("|              \\ \\  _ <'  / __`\\ /\\`'__\\/' _ `\\   /'__`\\  /',__\\            |");
        System.out.println("|               \\ \\ \\ \\ \\/\\ \\ \\ \\\\ \\ \\/ /\\ \\/\\ \\ /\\  __/ /\\__, `\\           |");
        System.out.println("|                \\ \\____/\\ \\____/ \\ \\_\\ \\ \\_\\ \\_\\\\ \\____\\\\/\\____/           |");
        System.out.println("|                 \\/___/  \\/___/   \\/_/  \\/_/\\/_/ \\/____/ \\/___/            |");
        System.out.println("|                                                                           |");
        System.out.println("+---------------------------------------------------------------------------+");
        System.out.println("|                   Welcome to Mille Bornes by TBDSoft!!                    |");
        System.out.println("|                                                                           |");
        System.out.println("|       Please maximize this window and then press Enter to start!          |");
        System.out.println("+===========================================================================+");
    } // end printMainSplash

    //#########################################################################
    void printPrelimInfoSplash()
    {
        cls();
        System.out.printf("+===========================================================================+\n");
        System.out.printf("|                                                                           |\n");
        System.out.printf("|                     _   _        __     __                                |\n");
        System.out.printf("|                    /'\\_/`\\   __ /\\_ \\  /\\_ \\                              |\n");
        System.out.printf("|                   /\\      \\ /\\_\\\\//\\ \\ \\//\\ \\       __                    |\n");
        System.out.printf("|                   \\ \\ \\__\\ \\\\/\\ \\ \\ \\ \\  \\ \\ \\    /'__`\\                  |\n");
        System.out.printf("|                    \\ \\ \\_/\\ \\\\ \\ \\ \\_\\ \\_ \\_\\ \\_ /\\  __/                  |\n");
        System.out.printf("|                     \\ \\_\\\\ \\_\\\\ \\_\\/\\____\\/\\____\\\\ \\____\\                 |\n");
        System.out.printf("|                      \\/_/ \\/_/ \\/_/\\/____/\\/____/ \\/____/                 |\n");
        System.out.printf("|              ____                                                         |\n");
        System.out.printf("|             /\\  _`\\                                                       |\n");
        System.out.printf("|             \\ \\ \\ \\ \\    ___    _ __    ___       __     ____             |\n");
        System.out.printf("|              \\ \\  _ <'  / __`\\ /\\`'__\\/' _ `\\   /'__`\\  /',__\\            |\n");
        System.out.printf("|               \\ \\ \\ \\ \\/\\ \\ \\ \\\\ \\ \\/ /\\ \\/\\ \\ /\\  __/ /\\__, `\\           |\n");
        System.out.printf("|                \\ \\____/\\ \\____/ \\ \\_\\ \\ \\_\\ \\_\\\\ \\____\\\\/\\____/           |\n");
        System.out.printf("|                 \\/___/  \\/___/   \\/_/  \\/_/\\/_/ \\/____/ \\/___/            |\n");
        System.out.printf("|                                                                           |\n");
        System.out.printf("+---------------------------------------------------------------------------+\n");
        System.out.printf("    Before you begin, you will need to answer a few questions...\n");
        System.out.printf("	1. What is your name?                                      Caleb\n");
        System.out.printf("    2. What is the name of your partner computer player?       Robert\n");
        System.out.printf("	3. What is the name of your team?                          The Monkeys\n");
        System.out.printf("	\n");
        System.out.printf("    4. What is the name of the computer player to your left?   Dave\n");
        System.out.printf("	5. What is the name of the computer player to your right?  Jonathan\n");
        System.out.printf("	6. What is the name of the computer team?                  The Losers  \n");
        System.out.printf("	\n");
        System.out.printf("	Thank you...The cards are now being dealt to start the game!\n");
        System.out.printf("\n");
        System.out.printf("+---------------------------------------------------------------------------+\n");
    } // end printPrelimInfoSplash


    //#########################################################################
    void printRoundOverSplash(Vector<Team> teamVect )
    {
        cls();
        System.out.printf("+===========================================================================+\n");
        System.out.printf("|                                                                           |\n");
        System.out.printf("|                     _   _        __     __                                |\n");
        System.out.printf("|                    /'\\_/`\\   __ /\\_ \\  /\\_ \\                              |\n");
        System.out.printf("|                   /\\      \\ /\\_\\\\//\\ \\ \\//\\ \\       __                    |\n");
        System.out.printf("|                   \\ \\ \\__\\ \\\\/\\ \\ \\ \\ \\  \\ \\ \\    /'__`\\                  |\n");
        System.out.printf("|                    \\ \\ \\_/\\ \\\\ \\ \\ \\_\\ \\_ \\_\\ \\_ /\\  __/                  |\n");
        System.out.printf("|                     \\ \\_\\\\ \\_\\\\ \\_\\/\\____\\/\\____\\\\ \\____\\                 |\n");
        System.out.printf("|                      \\/_/ \\/_/ \\/_/\\/____/\\/____/ \\/____/                 |\n");
        System.out.printf("|              ____                                                         |\n");
        System.out.printf("|             /\\  _`\\                                                       |\n");
        System.out.printf("|             \\ \\ \\ \\ \\    ___    _ __    ___       __     ____             |\n");
        System.out.printf("|              \\ \\  _ <'  / __`\\ /\\`'__\\/' _ `\\   /'__`\\  /',__\\            |\n");
        System.out.printf("|               \\ \\ \\ \\ \\/\\ \\ \\ \\\\ \\ \\/ /\\ \\/\\ \\ /\\  __/ /\\__, `\\           |\n");
        System.out.printf("|                \\ \\____/\\ \\____/ \\ \\_\\ \\ \\_\\ \\_\\\\ \\____\\\\/\\____/           |\n");
        System.out.printf("|                 \\/___/  \\/___/   \\/_/  \\/_/\\/_/ \\/____/ \\/___/            |\n");
        System.out.printf("|                                                                           |\n");
        System.out.printf("+---------------------------------------------------------------------------+\n");
        System.out.printf("    End of Hand! A team reached 1,000 miles!\n");
        System.out.printf("	\n");
        System.out.printf("	The current team scores are as follows:\n");
        System.out.printf("	    %-20s: %5d\n", teamVect.get(0).name[0], teamVect.get(0).gameScore );
        System.out.printf("		%-20s: %5d\n", teamVect.get(1).name[0], teamVect.get(1).gameScore );
        System.out.printf("		\n");
        System.out.printf("	Press the Enter key to begin the next hand...\n");
        System.out.printf("\n");
        System.out.printf("+---------------------------------------------------------------------------+\n");

    } // end printRoundOverSplash

    //#########################################################################
    void printGameOverSplash(Vector<Team> teamVect)
    {
        cls();
        System.out.printf("+===========================================================================+\n");
        System.out.printf("|                                                                           |\n");
        System.out.printf("|                                                                           |\n");
        System.out.printf("|                                                                           |\n");
        System.out.printf("|                                                                           |\n");
        System.out.printf("|                                                                           |\n");
        System.out.printf("|       __      __                                          __   __         |\n");
        System.out.printf("|      /\\ \\  __/\\ \\   __                                   /\\ \\ /\\ \\        |\n");
        System.out.printf("|      \\ \\ \\/\\ \\ \\ \\ /\\_\\     ___      ___       __   _ __ \\ \\ \\\\ \\ \\       |\n");
        System.out.printf("|       \\ \\ \\ \\ \\ \\ \\\\/\\ \\  /' _ `\\  /' _ `\\   /'__`\\/\\`'__\\\\ \\ \\\\ \\ \\      |\n");
        System.out.printf("|        \\ \\ \\_/ \\_\\ \\\\ \\ \\ /\\ \\/\\ \\ /\\ \\/\\ \\ /\\  __/\\ \\ \\/  \\ \\_\\\\ \\_\\     |\n");
        System.out.printf("|         \\ `\\___x___/ \\ \\_\\\\ \\_\\ \\_\\\\ \\_\\ \\_\\\\ \\____\\\\ \\_\\   \\/\\_\\\\/\\_\\    |\n");
        System.out.printf("|          '\\/__//__/   \\/_/ \\/_/\\/_/ \\/_/\\/_/ \\/____/ \\/_/    \\/_/ \\/_/    |\n");
        System.out.printf("|		                                                           |\n");
        System.out.printf("|		                                                           |\n");
        System.out.printf("|                       		                                    |\n");
        System.out.printf("|                                                                           |\n");
        System.out.printf("+---------------------------------------------------------------------------+\n");

        int winTeamIndex;
        if( teamVect.get(0).gameScore > teamVect.get(1).gameScore )
             winTeamIndex = 0;
        else winTeamIndex = 1;

        System.out.printf("    Congratulations, %s!!! You just won Mille Bornes!!!\n", teamVect.get(winTeamIndex).name[0] );
        System.out.printf("	\n");
        System.out.printf("	The final team scores are as follows:\n");
        System.out.printf("	    %-20s: %5d\n", teamVect.get(0).name[0], teamVect.get(0).gameScore );
        System.out.printf("		%-20s: %5d\n", teamVect.get(1).name[0], teamVect.get(1).gameScore );
        System.out.printf("		\n");
        System.out.printf("	Press any key to exit the program...\n");
        System.out.printf("\n");
        System.out.printf("+---------------------------------------------------------------------------+\n");

    } // end printGameOverSplash

}//end class UserInterface
